<template>
	<view class="content">
		<view class="headContent" style="padding-top: 30rpx;">
			<form>
				<view class="cu-form-group">
					<view class="title"><text style="font-size:18px;" class="iconfont">&#xe650;</text></view>
					<input type="text" placeholder="请输入手机号" v-model="phone" name="input" style="text-align: left;"></input>
				</view>
				<view class="cu-form-group">
					<view class="title"><text class="icon iconfont icon-user">&#xe632;</text></view>
			 		<input type="text" placeholder="请输入登录账号" v-model="userName" name="input" style="text-align: left;"></input>
				</view>
				<view class="cu-form-group">
					<view class="title"><text class="icon iconfont icon-yanzhengma-copy"></text></view>
					<input type="number" maxlength="6" v-model="code" placeholder="请填写验证码" name="input" style="text-align: left;"></input>
					<button @click="getCodeNum()" type="primary">{{!codeTime?'获取验证码':codeTime+'s'}}</button>
				</view>
				<view class="cu-form-group">
					<view class="title"><text class="icon iconfont icon-mima"></text></view>
					<input :type="typeName1" maxlength="13" v-model="newPwd" placeholder="请输入新密码" name="input" class="input"></input>
					<image @tap="changePwdType1()" v-if="isShow" src="../../static/eyes.png" style="width: 50rpx; height: 50rpx;" mode="aspectFit"></image>
					<image @tap="changePwdType1()" v-else src="../../static/eyes2.png" style="width: 50rpx; height: 50rpx;" mode="aspectFit"></image>
				</view>
			</form>
		</view>
	
		<view class="submit">
			<button @tap="submit()">
				确认
			</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				number1: 0,
				isShow: false,
				typeName1: "password",
				
				phone: '',
				code: '',
				newPwd: '',
				userName: '',
				
				codeTime: 0,
				appid:""
			}
		},
		methods: {
			changePwdType1() {
				if (this.number1 === 0) {
					this.isShow = true
					this.number1++
					this.typeName1 = "text"
				} else {
					this.isShow = false
					this.number1--
					this.typeName1 = "password"
				}
			},		
		
			submit() {
				var mobileReg=/^1[34578]\d{9}$/
				if(!mobileReg.test(this.phone)){
					uni.showToast({
						title:"请输入正确的手机号",
						icon: "none"
					})
					return;
				}
				else if (this.userName.toString() === "") {
					uni.showToast({
						title: "请填写登录名",
						icon: "none"
					})
					return;
				} else if (this.code.toString() === "") {
					uni.showToast({
						title: "请填写验证码",
						icon: "none"
					})
					return;
				} else if (this.newPwd.toString() === "") {
					uni.showToast({
						title: "请填写新密码",
						icon: "none"
					})
					return;
				} else {
					console.log(this.phone.toString(), this.userName.toString(), this.code, this.newPwd)
					uni.request({
						url: this.confige.webUrl + "/forgetPassword",
						method: "GET",
						data: {
							login_name: this.userName,
							mobile: this.phone.toString(),
							newpassword: this.newPwd.toString(),
							smsCode: this.code
						},
						success: (res) => {
							console.log(res)
							if (res.data.message == '重置密码成功！请妥善保管新密码'){
								uni.showModal({
									title: "提示",
									content: "重置密码成功！请妥善保管新密码",
									showCancel: false,
									success: (option) => {
										if (option.confirm) {
											uni.redirectTo({
												url: '../userLogin/userLogin'
											})
										}
									}
								})
							} else {
								uni.showModal({
									title: "提示",
									content: res.data.message,
									showCancel: false,
									success: (option) => {
										if (option.confirm) {
											return
										}
									}
								})
							}
						}
					})
				}
			},
			//获取验证码
			getCodeNum() {
				var pinf = plus.push.getClientInfo();
				console.log(pinf);
				this.appid = pinf.token;
				var mobileReg=/^1[34578]\d{9}$/
				if(!mobileReg.test(this.phone)){
					uni.showToast({
						title:"请输入正确的手机号",
						icon: "none"
					})
					return;
				}else{
					if (this.codeTime > 0) {
						uni.showToast({
							title: '不能重复获取',
							icon: "none"
						});
						return;
					}
					this.codeTime = 60;
					let timer = setInterval(() => {
						this.codeTime--;
						if (this.codeTime < 1) {
							clearInterval(timer);
							this.codeTime = 0;
						}
					}, 1000)
					uni.request({
						url: this.confige.webUrl + "/code/sms",
						data: {
							mobile: this.phone,
							appId:this.appid
						},
						success: (res) => {
							console.log(res);
							uni.showToast({
								icon:"none",
								title:res.data.data,
								duration:2000
							})
						}
					})
				}
				
			},
		},
		onReady() {
			
		}
	}
</script>

<style lang="less" scoped>
	@import "../../common/colorui/main.css";
	@import "../../common/colorui/icon.css";
	@import "../../common/global.less";
	@import "../../common/iconReg.css" ;
	page {
		width: 750rpx;
		height: 100%;
	}

	.content {
		width: 100%;
		height: 100%;
		background: #F6F6F6;
	}

	.headContent {
		width: 700rpx;
		margin-left: 25rpx;
	}

	.input {
		text-align: left;
		width: 100%;
		height: 100%;
		outline: medium;
		border: none;
		font-size: 30rpx;
		color: #555555;
		letter-spacing: 4rpx;
	}

	.cu-form-group>button {
		height: 80rpx;
		line-height: 80rpx;
		font-size: 26rpx;
		background: #4AC997;
		width: 200rpx;
	}

	.submit {
		width: 700rpx;
		margin-left: 25rpx;
		margin-top: 40rpx;
	}

	.submit>button {
		background: #4AC997;
		color: white;
		height: 90rpx;
		line-height: 90rpx;
		font-size: 32rpx;
	}
</style>
